---@class UIStoryMemory : UIBase
UIStoryMemory = UIBase.New(PanelResNames.UIStoryMemory)
local t = UIStoryMemory

function t.Init()
    UIBase.Init(t)
end

function t:OnCreate()
    self.btnClose = self:GetChild("btnBack")
    self.itemList = {}
    for i = 0, 4 do
        local item = self:GetChild("item"..i)
        local bg = item:GetChild("bg")
        local head = item:GetChild("head")
        local nameText = item:GetChild("chapName")
        local numText = item:GetChild("chapNum")
        self:RegisterOnClick(item,self.ClickChapter,nil,i+1)
        table.insert(self.itemList,{go = item,bg = bg,head = head,nameText = nameText,numText = numText});
    end
    self:RegisterOnClick(self.btnClose,self.OnBack)
end

function t:OnEnable()
    self:InitChapter()
end
function t:OnDisable()
end
function t:OnDestroy()
end
function t:InitChapter()
    local CrystalDic= dataTable.getDataTable("t_memorycrystal")
    local Count=1;
    for k,v in pairsByKeys(CrystalDic) do
        local item =self.itemList[Count];
        if item then
            item.go.visible = true
            item.bg.url = "ui://UIStoryMemeryList/"..v.f_CrystalPic
            item.head.url = "ui://UIStoryMemeryList/"..v.f_CharaPic
            item.nameText.text = getLanguage(v.f_CrystalName1);
            item.numText.text = getLanguage(v.f_CrystalName2);
            item.id = k
            Count=Count+1
        end
    end
    for i = Count, #self.itemList do
        self.itemList[i].go.visible = false
    end
end
function t:ClickChapter(index)
    local item = self.itemList[index]
    logicMgr.UIShowManager.ShowUIStoryMemoryList(item.id)
end
return t